package club.beimeng.emailserver.utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class BMResult {
    private static final int SUCCESS = 200;

    private static final int ERROR = 201;

    @ApiModelProperty(value = "是否成功le")
    private boolean success;

    @ApiModelProperty(value = "返回de码")
    private Integer code;

    @ApiModelProperty(value = "返回de消息")
    private String message;

    @ApiModelProperty(value = "返回de数据")
    private Map<String,Object> data = new HashMap<>();

    private BMResult(){} // 构造参数私有化

    /*成功静态方法*/
    public static BMResult ok(){
        BMResult bmResult = new BMResult();
        bmResult.setSuccess(true);
        bmResult.setCode(BMResult.SUCCESS);
        bmResult.setMessage("成功");
        return bmResult;
    }
    /*失败静态方法*/
    public static BMResult error(){
        BMResult bmResult = new BMResult();
        bmResult.setSuccess(false);
        bmResult.setCode(BMResult.ERROR);
        bmResult.setMessage("失败");
        return bmResult;
    }


    /*返回自身可以做到链式编程*/
    public BMResult success(Boolean value){
        this.setSuccess(value);
        return this;
    }

    public BMResult message(String message){
        this.setMessage(message);
        return this;
    }

    public BMResult code(Integer code){
        this.setCode(code);
        return this;
    }

    public BMResult data(String key,Object value){
        this.data.put(key,value);
        return this;
    }
}
